package com.teamwork.shareplatform.service.impl;

import com.teamwork.shareplatform.entity.Subject;
import com.teamwork.shareplatform.mapper.SubjectMapper;
import com.teamwork.shareplatform.service.SubjectService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SubjectServiceImpl implements SubjectService {

    @Resource
    SubjectMapper subjectMapper;

    @Override
    public List<Subject> queryAll() {
        try {
            return subjectMapper.queryAll();
        } catch (Exception e) {
            // 建议使用日志框架记录异常，这里简单打印
            System.err.println("查询所有科目时出现异常: " + e.getMessage());
            return null;
        }
    }

    @Override
    public List<Subject> queryByLevel() {
        try {
            return subjectMapper.queryByLevel();
        } catch (Exception e) {
            System.err.println("查询指定层级科目时出现异常: " + e.getMessage());
            return null;
        }
    }

    @Override
    public List<Subject> queryByParent(int id) {
        try {
            return subjectMapper.queryByParent(id);
        } catch (Exception e) {
            System.err.println("根据父科目 ID 查询子科目时出现异常: " + e.getMessage());
            return null;
        }
    }

}